(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.popup.sitetplRoleViewController', sitetplRoleViewController);
	sitetplRoleViewController.$inject = [ '$scope', '$timeout', '$q', '$uibModalInstance', 'Constants', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig' , 'authService', 'ajaxServiceFactory', 'validatorConfig', 'arithService'];
	function sitetplRoleViewController($scope, $timeout, $q, $uibModalInstance, Constants, dialogsModule, gridService, modalService, layoutConfig, authService, ajaxServiceFactory, validatorConfig, arithService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("sitetplRoleViewController"), ajaxService = ajaxServiceFactory.buildAjaxService({
		});
		ctrl.dialogsModule = dialogsModule;
//		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.sitetplRole = {};
		ctrl.formName = "sitetplRoleForm";
		
		ctrl.init = function() {
			ctrl.sitetplRoleRightInnerGridOptions = gridService.createInnerGridOptions($scope, layoutConfig.formConfigs.sitetplRoleRight.tableConfigs.table, ctrlProfLimitFaciAttrRowSelectionChanged);
			ctrl.sitetplRoleRightInnerGridOptions.data = 'vm.sitetplRole.sitetplRoleRights';
			ctrl.sitetplRoleRightInnerGridOptions.verifyData = 'vm.sitetplRoleOld.sitetplRoleRights';
			ctrl.sitetplRoleRightInnerGridOptions.enableRowHeaderSelection = false;
			function ctrlProfLimitFaciAttrRowSelectionChanged(eventRow, selectedRows) {
				ctrl.selectedProfLimitFaciAttrs = selectedRows;
			}
			// init general
			var initSitetplRole = ctrl.dialogsModule.params.sitetplRole || {};
			ctrl.layoutConfig = layoutConfig;
			$timeout(function() {
				ctrl.sitetplRole = initSitetplRole;
				ctrl.sitetplRoleOld = ctrl.dialogsModule.params.sitetplRoleOld;
				if (ctrl.sitetplRoleOld)
					ctrl.sitetplRoleOld.sitetplRoleRights = ctrl.sitetplRoleOld.sitetplRoleRights || [];
			});
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
	}
})(angular);
